package vip.xiaonuo.bi.modular.datasource.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import vip.xiaonuo.bi.modular.dataset.entity.DataColumns;
import vip.xiaonuo.bi.modular.datasource.dto.Colunm;
import vip.xiaonuo.bi.modular.datasource.mapper.DataColumnsMapper;
import vip.xiaonuo.bi.modular.datasource.service.DataColumnsService;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 数据源分类表Service接口实现类
 *
 * @author 顾育司
 * @date  2023/12/15 12:09
 **/
@Service
public class DataColumnsServiceImpl extends ServiceImpl<DataColumnsMapper, DataColumns> implements DataColumnsService {


    @Override
    public void saveCols(List<Colunm> colunms, String dataSetId, Map<String, String> columnType) {
       if (colunms==null){
           return;
       }
       List<DataColumns> columns = new ArrayList<>();
        for (int i = 0; i < colunms.size(); i++) {
            DataColumns dataColumns = new DataColumns();
            Colunm colunm = colunms.get(i);
            String name = colunm.getName(); // 原始名称
            String type = colunm.getType();
            String alias = colunm.getAlias();// 别称
            dataColumns.setName(name);
            dataColumns.setType(type);
            dataColumns.setAlias(alias);


        }
    }

    @Override
    public void updateByColId(Long id, String alias, String calculate) {
        DataColumns dataColumns = new DataColumns();
        dataColumns.setId(id+"");
        dataColumns.setAlias(alias);
        dataColumns.setCalculate(calculate);
        this.updateById(dataColumns);
    }
}